<?php 
if (!defined('e107_INIT')) { exit; }
require_once(e_HANDLER.'shortcode_handler.php');
global $tp;
$product_shortcodes = $tp->e_sc->parse_scbatch(__FILE__);

/*

SC_BEGIN PRODUCTS_LIST
    global $shop_settings, $e107, $eplug_folder, $PLUGINS_DIRECTORY, $category_id;
    $item = getcachedvars('e107shop_products');
    foreach ($item as $record) {
        if ($record["customize"] == 1) {
            $text .= "<form name='products' action='product_details.php?product=".$record["ProductID"]."&cat=".$category_id."' method='post'>";
        } else {
            $text .= "<form name='products' action='cart.php?action=add' method='post'>";
        }
        // If there is no image or image is gone aka deleted, set to default
        if ($record['ProductIcon'] == "") {
            $record["ProductIcon"] = 'noimgbig.jpg';
        }
        $picturedir = "images/products/".$records['ProductIcon'];
        $imageFound = file_exists($picturedir);
        $text .= "<tr>";
        // Display the small image with a link to the details image
        $text .= "<td class='forumheader3' style='padding: 10px; text-align: ".$shop_settings['product_list_align_picture'].";'>";
        if ($imageFound) {
            $text .= "<a href='product_details.php?product=".$record["ProductID"]."&cat=".$category_id."'>
            <img src='".e_IMAGE_ABS."thumb.php?".$e107->file_path.$PLUGINS_DIRECTORY.$eplug_folder."/images/products/".$record["ProductIcon"]."+".$shop_settings['thumbnail_size']."+noscale' border='0'></a>";
        } else {
            $text .= "Image<br />Not<br />Found";
        }
        $text .= "</td>";
        // Display the product Name with same link as above
        $text .= "<td class='forumheader3' style='text-align: ".$shop_settings['product_list_align_name'].";'>
                    <a href='product_details.php?product=".$record["ProductID"]."&cat=".$category_id."'>".$record["ProductName"]."</a>
                 </td>";
        // Display the price
        if ($record["special"] == "") {
            $text .= "    <td class='forumheader3' style='text-align: ".$shop_settings['product_list_align_price'].";'>
                                    <center>".$shop_settings["currency_symbol"].e107shop_get_numformat($record["ProductPrice"]);
        } else {
            $text .= "    <td class='forumheader3' style='text-align: ".$shop_settings['product_list_align_price'].";'>
                                    <center>".lan_product_was.": ".$shop_settings["currency_symbol"].
                "<strike>".e107shop_get_numformat($record["ProductPrice"])."</strike> ".lan_product_now.": ".
                $shop_settings["currency_symbol"].e107shop_get_numformat($record["special"]);
        }
        if ($shop_settings['product_list_admin'] == 'on' && ADMIN) {
            $text .= "
            <br />
            <div style='height: 10px;'>
                &nbsp;
            </div>
            <fieldset>
            <legend>Admins Only</legend>
            <a href='admin/admin_manage_products.php?a=1&p={$record["ProductID"]}'>
                <img src='".e_IMAGE."admin_images/edit_16.png' border='0' />
            </a>
            &nbsp;
            <a href='admin/admin_manage_products.php?p={$record["ProductID"]}'>
                <img src='".e_IMAGE."fileinspector/expand.png' border='0' height='15' width='15' />
            </a>
            &nbsp;";
            if ($shop_settings['product_list_admin_delete']=='delete')
                $text .= "<a href='admin/admin_manage_products.php?a=2&p={$record["ProductID"]}'>";
            else
                $text .= "<a href='admin/admin_manage_products.php?a=3&p={$record["ProductID"]}'>";
            $text .= "
                <img src='".e_IMAGE."filemanager/del.png' border='0' height='15' width='15' />
            </a>
            </fieldset>
            </center></td>";
        } else {
            $text .= "</center></td>";
        }
        // continue the foreach if they want less than 5 columns
        if ($shop_settings['product_list_view'] < 5) {
            $text .= "</form></tr>";
            continue;
        }
        // Display quantity
        $text .= "  <td class='forumheader3' style='text-align: ".$shop_settings['product_list_align_quant'].";'>
                            <center>
                                <input style='text-align: center;' type='text' name='quantity' value='1' size='2' class='tbox' />
                            </center>
                        </td>";
        // Display the product options in a select box
        //
        $text .= "        <td class='forumheader3' style='padding: 10px; text-align: ".$shop_settings['product_list_align_action'].";'>
                                    ".e107shop_get_products_options($record["ProductID"]);
        // Add a hidden field that holds the product ID for form submittal
        $text .= "<input type='hidden' name='product' value='".$record["ProductID"]."' />";
        // Display the "add to cart" button if there is stock on hand
        // or if they want to sell into negitive items
        //
        if ($shop_settings["sell_into_minus_stock"] == 1) {
            if ($record["customize"] == 1) {
                $text .= "<input class='button' type='submit' name='feature' value='".lan_custom."'></td>";
            } else {
                $text .= "<input class='button' type='submit' name='addcart' value='".lan_add_to_cart."'></td>";
            }
        } else {
            if (e107shop_get_product_field($record["ProductID"], "stock_on_hand") > 0) {
                if ($record["customize"] == 1) {
                    $text .= "<input class='button' type='submit' name='submit' value='".lan_custom."'></td>";
                } else {
                    $text .= "<input class='button' type='submit' name='addcart' value='".lan_add_to_cart."' /></td>";
                }
            } else {
                $text .= "<span style='color: red;'>".lan_not_in_stock."</span></td>";
            }
        }
        $text .= "</form></tr>";
    }
    return $text;
SC_END

SC_BEGIN PRODUCT_NAME
    $item = getcachedvars('e107shopproductdetails');
    return $item['product_name'];
SC_END

SC_BEGIN PRODUCT_PRICE
    global $shop_settings;
    $item = getcachedvars('e107shopproductdetails');
    if ($item['special_price']=='') return $shop_settings["currency_symbol"].e107shop_get_numformat($item["product_price"]);
    else return "<strike>".$shop_settings["currency_symbol"].$item["product_price"]."</strike> - ".lan_product_now.": ".$shop_settings["currency_symbol"].e107shop_get_numformat($item["special_price"]);
SC_END

SC_BEGIN PRODUCT_IMAGE
    global $e107, $category_id, $PLUGINS_DIRECTORY, $eplug_folder, $shop_settings;
    $item = getcachedvars('e107shopproductdetails');
    if ($item['large_image'] == "") {
        $item['large_image'] = 'noimgbig.jpg';
    }
    $picturedir = "images/products/".$item['large_image'];
    $imageFound = file_exists($picturedir);
    // Display the small image with a link to the details image
    if ($imageFound) {
        $text .= "<a href='images/products/".$item['large_image']."' target='_blank'>
        <img src='".e_IMAGE_ABS."thumb.php?".$e107->file_path.$PLUGINS_DIRECTORY.$eplug_folder."/images/products/".$item['large_image']."+".intval($shop_settings['thumbnail_size']+100)."+noscale' border='0'></a>";
    } else {
        $text .= "Image<br />Not<br />Found";
    }
    if ($item["thumb_only"] == "2") {
        return $text;
    }
    return;
SC_END

SC_BEGIN PRODUCT_OPTIONS
    $item = getcachedvars('e107shopproductdetails');
    return $item['product_options'];
SC_END

SC_BEGIN PRODUCT_ORDER
    global $shop_settings, $category_order_class;
    $item = getcachedvars('e107shopproductdetails');
    $product_ID = $item['ID'];
    $text = "<center><table><tr>";
    if ($shop_settings["sell_into_minus_stock"] == 1) {
        $text .= "<td><input style='text-align: center;' type='text' name='quantity' size='2' value='1' /><input type='hidden' name='product' value='".$product_ID."' /></td>";
        $text .= "<td width='10'>&nbsp;</td><td><input class='button' type='submit' name='submit' value='".lan_add_to_cart."' /></td>";
    } else {
        if ($item['stock_on_hand'] > 0) {
            $text .= "<td><input style='text-align: center;' type='text' name='quantity' size='2' value='1' /><input type='hidden' name='product' value='".$product_ID."' /></td>";
            $text .="<td width='10'>&nbsp;</td><td><input class='button' type='submit' name='submit' value='".lan_add_to_cart."' /></td>";
        } else $text .= "<td style='color: red;'>".lan_not_in_stock."</td>";
    }
    $text .= "</tr></table></center>";
    return $text;
SC_END

SC_BEGIN PRODUCT_DESCRIPTION
    global $tp;
    $item = getcachedvars('e107shopproductdetails');
    return $tp->toHTML($item['description'], true);
SC_END

SC_BEGIN PRODUCT_CUSTOMIZE
    $item = getcachedvars('e107shopproductdetails');
    $text = "<center><table>";
    if ($item["customize"] == 1) {
        $i = 1;
        $custom_loop = $item["cust_cat"];
        while ($i <= $custom_loop) {
            if ($i > 1) $text .= "<tr><td colspan='3' style='height: 5px;'> </td></tr>";
            $text .= e107shop_feature_field("field".$i, $item["fname_".$i]);
            $i++;
        }
    } else return;
    $text .= "</table></center>";
    return $text;
SC_END

*/
